/*
 * @Author: SamZhang SamZhang@apjcorp.com
 * @Date: 1985-10-26 16:15:00
 * @LastEditors: SamZhang samzhang@apjcorp.com
 * @LastEditTime: 2022-11-29 10:35:56
 * @FilePath: /circulation-web/src/my_modules/opds-web-client/lib/components/context/ActionsContext.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useActions = exports.ActionsProvider = exports.ActionsContext = void 0;
var React = require("react");
var useThunkDispatch_1 = require("../../hooks/useThunkDispatch");
exports.ActionsContext = React.createContext(undefined);
function ActionsProvider(_a) {
    var children = _a.children, actions = _a.actions, fetcher = _a.fetcher;
    return (React.createElement(exports.ActionsContext.Provider, { value: { actions: actions, fetcher: fetcher } }, children));
}
exports.ActionsProvider = ActionsProvider;
/**
 * Custom hook used for getting access to the available Actions.
 */
function useActions() {
    var context = React.useContext(exports.ActionsContext);
    var dispatch = useThunkDispatch_1.default();
    if (typeof context === "undefined") {
        throw new Error("useActions must be used within a ActionsProvider");
        // console.error("useActions must be used within a ActionsProvider")
    }
    var actions = context.actions, fetcher = context.fetcher;
    return { actions: actions, fetcher: fetcher, dispatch: dispatch };
}
exports.useActions = useActions;
exports.default = exports.ActionsContext;
